//package com.cdxy.config.rabbitmq;
//
//import com.cdxy.enums.mq.RabbitExchangeEnum;
//import com.cdxy.enums.mq.RabbitQueueEnum;
//import com.cdxy.enums.mq.RabbitRoutingKeyEnum;
//import org.springframework.amqp.core.*;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//
//import java.util.HashMap;
//import java.util.Map;
//
///**
// * @Author: tangy
// * @Date: 2020/6/8 15:12
// */
//@Configuration
//public class RabbitMqConfig {
//
//    @Bean("businessExchange")
//    public FanoutExchange businessExchange() {
//        return new FanoutExchange(RabbitExchangeEnum.BUSINESS.getCode());
//    }
//
//    @Bean("deadLetterExchange")
//    public DirectExchange deadLetterExchange() {
//        return new DirectExchange(RabbitExchangeEnum.DEAD_LETTER.getCode());
//    }
//
//    @Bean("businessQueueA")
//    public Queue businessQueueA() {
//        final Map<String, Object> args = new HashMap<>(2);
//        args.put("x-dead-letter-exchange", RabbitExchangeEnum.DEAD_LETTER.getCode());
//        args.put("x-dead-letter-routing-key", RabbitRoutingKeyEnum.DEAD_LETTER_QUEUE_A.getCode());
//        return QueueBuilder.durable(RabbitQueueEnum.BUSINESS_QUEUE_A.getQueueName()).withArguments(args).build();
//    }
//
//    @Bean("businessQueueB")
//    public Queue businessQueueB() {
//        final Map<String, Object> args = new HashMap<>(2);
//        args.put("x-dead-letter-exchange", RabbitExchangeEnum.DEAD_LETTER.getCode());
//        args.put("x-dead-letter-routing-key", RabbitRoutingKeyEnum.DEAD_LETTER_QUEUE_B.getCode());
//        return QueueBuilder.durable(RabbitQueueEnum.BUSINESS_QUEUE_B.getQueueName()).withArguments(args).build();
//    }
//
//    @Bean("deadLetterQueueA")
//    public Queue deadLetterQueueA() {
//        return new Queue(RabbitQueueEnum.DEAD_LETTER_A.getQueueName());
//    }
//
//    @Bean("deadLetterQueueB")
//    public Queue deadLetterQueueB() {
//        return new Queue(RabbitQueueEnum.DEAD_LETTER_B.getQueueName());
//    }
//
//    @Bean
//    public Binding businessBindingA(@Qualifier("businessQueueA") Queue queue, @Qualifier("businessExchange") FanoutExchange exchange) {
//        return BindingBuilder.bind(queue).to(exchange);
//    }
//
//    @Bean
//    public Binding businessBindingB(@Qualifier("businessQueueB") Queue queue, @Qualifier("businessExchange") FanoutExchange exchange) {
//        return BindingBuilder.bind(queue).to(exchange);
//    }
//
//    @Bean
//    public Binding deadLetterBindingA(@Qualifier("deadLetterQueueA") Queue queue, @Qualifier("deadLetterExchange") DirectExchange exchange) {
//        return BindingBuilder.bind(queue).to(exchange).with(RabbitRoutingKeyEnum.DEAD_LETTER_QUEUE_A.getCode());
//    }
//
//    @Bean
//    public Binding deadLetterBindB(@Qualifier("deadLetterQueueB") Queue queue, @Qualifier("deadLetterExchange") DirectExchange exchange) {
//        return BindingBuilder.bind(queue).to(exchange).with(RabbitRoutingKeyEnum.DEAD_LETTER_QUEUE_B.getCode());
//    }
//
//
//    /**
//     * 延迟队列
//     *
//     * @return
//     */
//    @Bean("delayBusinessExchange")
//    public DirectExchange delayBusinessExchange() {
//        return new DirectExchange(RabbitExchangeEnum.DELAY_BUSINESS.getCode());
//    }
//
//    @Bean("delayDeadLetterExchange")
//    public DirectExchange delayDeadLetterExchange() {
//        return new DirectExchange(RabbitExchangeEnum.DELAY_DEAD_LETTER.getCode());
//    }
//
//    @Bean("delayBusinessQueueA")
//    public Queue delayBusinessQueueA() {
//        Map<String, Object> args = new HashMap<>(3);
//        args.put("x-dead-letter-exchange", RabbitExchangeEnum.DELAY_DEAD_LETTER.getCode());
//        args.put("x-dead-letter-routing-key", RabbitQueueEnum.DELAY_DEAD_LETTER_A.getRabbitRoutingKeyEnum().getCode());
//        args.put("x-message-ttl", 6000);
//        return QueueBuilder.durable(RabbitQueueEnum.DELAY_BUSINESS_QUEUE_A.getQueueName()).withArguments(args).build();
//    }
//
//    @Bean("delayBusinessQueueB")
//    public Queue delayBusinessQueueB() {
//        Map<String, Object> args = new HashMap<>(3);
//        args.put("x-dead-letter-exchange", RabbitExchangeEnum.DELAY_DEAD_LETTER.getCode());
//        args.put("x-dead-letter-routing-key", RabbitQueueEnum.DELAY_DEAD_LETTER_B.getRabbitRoutingKeyEnum().getCode());
//        args.put("x-message-ttl", 8000);
//        return QueueBuilder.durable(RabbitQueueEnum.DELAY_BUSINESS_QUEUE_B.getQueueName()).withArguments(args).build();
//    }
//
//    @Bean("delayDeadLetterQueueA")
//    public Queue delayDeadLetterQueueA() {
//        return new Queue(RabbitQueueEnum.DELAY_DEAD_LETTER_A.getQueueName());
//    }
//    @Bean("delayDeadLetterQueueB")
//    public Queue delayDeadLetterQueueB() {
//        return new Queue(RabbitQueueEnum.DELAY_DEAD_LETTER_B.getQueueName());
//    }
//
//    @Bean
//    public Binding delayBusinessABindExchange(@Qualifier("delayBusinessQueueA") Queue queue, @Qualifier("delayBusinessExchange") DirectExchange exchange) {
//        return BindingBuilder.bind(queue).to(exchange).with(RabbitQueueEnum.DELAY_BUSINESS_QUEUE_A.getRabbitRoutingKeyEnum().getCode());
//    }
//
//    @Bean
//    public Binding delayBusinessBBindExchange(@Qualifier("delayBusinessQueueB") Queue queue, @Qualifier("delayBusinessExchange") DirectExchange exchange) {
//        return BindingBuilder.bind(queue).to(exchange).with(RabbitQueueEnum.DELAY_BUSINESS_QUEUE_B.getRabbitRoutingKeyEnum().getCode());
//    }
//
//    @Bean
//    public Binding delayDeadLetterABindExchange(@Qualifier("delayDeadLetterQueueA") Queue queue, @Qualifier("delayDeadLetterExchange") DirectExchange exchange) {
//        return BindingBuilder.bind(queue).to(exchange).with(RabbitQueueEnum.DELAY_DEAD_LETTER_A.getRabbitRoutingKeyEnum().getCode());
//    }
//
//    @Bean
//    public Binding delayDeadLetterBBindExchange(@Qualifier("delayDeadLetterQueueB") Queue queue, @Qualifier("delayDeadLetterExchange") DirectExchange exchange) {
//        return BindingBuilder.bind(queue).to(exchange).with(RabbitQueueEnum.DELAY_DEAD_LETTER_B.getRabbitRoutingKeyEnum().getCode());
//    }
//
//
//}
